// 初始化地图的设定
import TileLayer from "ol/layer/Tile";
import {BingMaps} from "ol/source";
import XYZ from "ol/source/XYZ";
import OSM from "ol/source/OSM";

const bingMapsKey = 'AmCyjKfPhTKluJM2pd6H3aY3s5TYn1ub4sWtO8LyWh-fbOQbCuUV5HPxaJ_EDJ6T';
// 创建Bing地图瓦片图层
const bingMapLayer = new TileLayer({
    visible: true, // 设置图层可见
    key: 'bingMapLayer',
    source: new BingMaps({
        key: bingMapsKey, // 设置API密钥
        imagerySet: 'Aerial', // 设置卫星图像
        crossOrigin: "anonymous"
    }),
});
const satelliteLayer = new TileLayer({
    visible: false, // 设置图层可见
    key: 'satelliteLayer',
    source: new XYZ({
        url: 'http://t{0-7}.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=7786923a385369346d56b966bb6ad62f',
        crossOrigin: "anonymous"
    })
});
const satelliteLabelLayer = new TileLayer({
    visible: false, // 设置图层可见
    key: 'satelliteLabelLayer',
    source: new XYZ({
        url: 'http://t{0-7}.tianditu.com/DataServer?T=cia_w&x={x}&y={y}&l={z}&tk=7786923a385369346d56b966bb6ad62f',
        crossOrigin: "anonymous"
    })
});

const streetLayer = new TileLayer({
    visible: false, // 设置图层可见
    key: 'streetLayer',
    source: new XYZ({
        url: 'http://t{0-7}.tianditu.com/DataServer?T=vec_w&x={x}&y={y}&l={z}&tk=7786923a385369346d56b966bb6ad62f',
        crossOrigin: "anonymous"
    })
});
const streetLabelLayer = new TileLayer({
    visible: false, // 设置图层可见
    key: 'streetLabelLayer',
    source: new XYZ({
        url: 'http://t{0-7}.tianditu.com/DataServer?T=cva_w&x={x}&y={y}&l={z}&tk=7786923a385369346d56b966bb6ad62f',
        crossOrigin: "anonymous"
    })
});
const terLayer = new TileLayer({
    visible: false, // 设置图层可见
    key: 'terLayer',
    source: new XYZ({
        url: 'http://t{0-7}.tianditu.com/DataServer?T=ter_w&x={x}&y={y}&l={z}&tk=7786923a385369346d56b966bb6ad62f',
        crossOrigin: "anonymous"
    })
});
const osmLayer = new TileLayer({
    key: 'osmLayer',
    visible: false, // 设置图层可见
    source: new OSM()
});

const arcgisImgLayer = new TileLayer({//arcgis影像
    visible: false,
    key: 'arcgisImgLayer',
    source: new XYZ({
        url: 'https://server.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
        crossOrigin: "anonymous"
    })
});
const arcgisVecLayer = new TileLayer({//arcgis街道
    visible: false,
    key: 'arcgisVecLayer',
    source: new XYZ({
        url: 'http://cache1.arcgisonline.cn/arcgis/rest/services/ChinaOnlineCommunity/MapServer/tile/{z}/{y}/{x}',
        crossOrigin: "anonymous"
    })
});
const googleImgLayer = new TileLayer({//谷歌影像
    visible: false,
    key: 'googleImgLayer',
    source: new XYZ({
        url: 'http://www.google.cn/maps/vt?lyrs=s@189&gl=cn&x={x}&y={y}&z={z}',
        crossOrigin: "anonymous"
    })
});
const googleVecLayer = new TileLayer({//谷歌街道
    visible: false,
    key: 'googleVecLayer',
    source: new XYZ({
        url: 'http://www.google.cn/maps/vt?lyrs=m@189&gl=cn&x={x}&y={y}&z={z}',
        crossOrigin: "anonymous"
    })
});
const gaodeImgLayer = new TileLayer({//高德影像
    visible: false,
    key: 'gaodeImgLayer',
    source: new XYZ({
        url: 'http://webst0{1-4}.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}',
        crossOrigin: "anonymous"
    })
});
const gaodeVecLayer = new TileLayer({//高德街道
    visible: false,
    key: 'gaodeVecLayer',
    source: new XYZ({
        url: 'http://webrd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}',
        crossOrigin: "anonymous"
    })
});
// 图层组
const layersData = [
    bingMapLayer,
    satelliteLayer,
    streetLayer,
    terLayer,
    satelliteLabelLayer,
    streetLabelLayer,
    osmLayer,
    arcgisImgLayer,
    arcgisVecLayer,
    googleImgLayer,
    googleVecLayer,
    gaodeImgLayer,
    gaodeVecLayer,
];

const mapconfig = [
    {"layer_id": "bingMapLayer", "label": "必应卫星", "className": "imgType"},//bing卫星图
    {"layer_id": "satelliteLayer", "label": "天地卫星", "className": "imgType"},//天地图卫星图
    {"layer_id": "streetLayer", "label": "天地街道", "className": "vecType"},//天地图街道图
    {"layer_id": "satelliteLabelLayer", "label": "街道标注", "className": "vecType"},//天地图卫星混合图
    {"layer_id": "streetLabelLayer", "label": "天地行政", "className": "vecType"},//天地图地形混合图
    {"layer_id": "terLayer", "label": "天地地形", "className": "terType"},//天地图地形图
    {"layer_id": "osmLayer", "label": "OSM", "className": "vecType"},//OSM地图
    {"layer_id": "arcgisImgLayer", "label": "esri影像", "className": "imgType"},//arcgis影像
    {"layer_id": "arcgisVecLayer", "label": "esri街道", "className": "vecType"},//arcgis街道
    {"layer_id": "googleImgLayer", "label": "谷歌影像", "className": "imgType"},//谷歌影像
    {"layer_id": "googleVecLayer", "label": "谷歌街道", "className": "vecType"},//谷歌街道
    {"layer_id": "gaodeImgLayer", "label": "高德影像", "className": "imgType"},//高德影像
    {"layer_id": "gaodeVecLayer", "label": "高德街道", "className": "vecType"},//高德街道
];
// console.log(mapconfig)


export {layersData, mapconfig}
